package com.css.bjdt_core.queryReportExamine.service;

import java.util.List;
import java.util.Map;
import java.util.Random;

import org.nutz.dao.Cnd;
import org.nutz.dao.Condition;
import org.nutz.dao.Dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.css.bjdt_core.queryReportExamine.entity.QueryReportExamine;
import com.css.bjdt_core.reportPrepare.entity.RptUnit;
import com.css.bjdt_core.reportPrepare.service.RptUnitService;
import com.css.bjdt_core.util.PageQuerys;

@Service
public class QueryReportExamineService {
	@Autowired
	private Dao dao;
	@Autowired
	private RptUnitService rptUnitService;

	/**
	 * 分页查询所有需要审核的报表
	 * @param cnd
	 * @return
	 */
	public Map queryPage( int pageNum, int pageSize,String unitId) {
		Map result = PageQuerys.ligerGridQuery(dao, QueryReportExamine.class, Cnd.where("UNIT_ID", "=", unitId), pageNum, pageSize);
		return result;
	}
	public Map queryPage(Condition cnd, int pageNum, int pageSize) {
		Map result = PageQuerys.ligerGridQuery(dao, QueryReportExamine.class, cnd, pageNum, pageSize);
		return result;
	}
	public QueryReportExamine getByDzzID(String unitId) {
		return dao.fetch(QueryReportExamine.class, Cnd.where("UNIT_ID", "=", unitId));
	}
	public Map queryPage(int pageNum, int pageSize, List<String> unitIds) {
		Condition cnd = Cnd.where("UNIT_ID", "IN", unitIds);
		return PageQuerys.ligerGridQuery(dao, RptUnit.class, cnd, pageNum, pageSize);
	}
	public void insert(String unitId) {
		RptUnit  unit =  rptUnitService.queryById(unitId);
		Random r = new Random();
		QueryReportExamine queryReportExamine = new QueryReportExamine();
		queryReportExamine.setUnitId(unit.getId());
		queryReportExamine.setUnitName(unit.getName());
		queryReportExamine.setDataError(""+r.nextInt(100));
		queryReportExamine.setNotDataError(""+r.nextInt(100));
		queryReportExamine.setRatio(""+r.nextInt(10)+"%");
		dao.insert(queryReportExamine);
	}
	public void delete(String unitId) {
		Condition cnd = Cnd.where("UNIT_ID", "=", unitId);
		dao.clear(QueryReportExamine.class, Cnd.where("UNIT_ID", "=", unitId));
	}

}
